package com.jeesite.modules.dp.web.order;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.dp.entity.order.DpOrder;
import com.jeesite.modules.dp.service.order.DpOrderService;

/**
 * 订单管理Controller
 * @author hancing
 * @version 2024-12-06
 */
@Controller
@RequestMapping(value = "${adminPath}/dp/order/dpOrder")
public class DpOrderController extends BaseController {

	@Autowired
	private DpOrderService dpOrderService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DpOrder get(String id, boolean isNewRecord) {
		return dpOrderService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("dp:order:dpOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(DpOrder dpOrder, Model model) {
		model.addAttribute("dpOrder", dpOrder);
		return "modules/dp/order/dpOrderList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("dp:order:dpOrder:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DpOrder> listData(DpOrder dpOrder, HttpServletRequest request, HttpServletResponse response) {
		dpOrder.setPage(new Page<>(request, response));
		Page<DpOrder> page = dpOrderService.findPage(dpOrder);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("dp:order:dpOrder:view")
	@RequestMapping(value = "form")
	public String form(DpOrder dpOrder, Model model) {
		model.addAttribute("dpOrder", dpOrder);
		return "modules/dp/order/dpOrderForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("dp:order:dpOrder:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DpOrder dpOrder) {
		dpOrderService.save(dpOrder);
		return renderResult(Global.TRUE, text("保存订单成功！"));
	}
	
}